package com.zhp.web;

import com.zhp.pojo.HOrder;
import com.zhp.pojo.HUser;
import com.zhp.service.impl.OrderServiceImpl;
import com.zhp.utils.DateUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author Lone Ranger
 */
@WebServlet("/addOrder")
public class AddOrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String edid = req.getParameter("edid");
        String dmoney = req.getParameter("dmoney");
        String odate = req.getParameter("odate");
        String sjdid = req.getParameter("sjdid");
        String sickness = req.getParameter("sickness");
        HttpSession session = req.getSession();
        HUser u = (HUser) session.getAttribute("u");
        HOrder hOrder = new HOrder();
        hOrder.setEdid(Integer.parseInt(edid));
        hOrder.setOdate(DateUtil.strToDate(odate));
        hOrder.setSjdid(Integer.parseInt(sjdid));
        hOrder.setSickness(sickness);
        hOrder.setGhf(Double.parseDouble(dmoney));

        // 把用户提交的预约单的初始状态改为预约中
        hOrder.setYyztid(21);
        hOrder.setUdid(u.getUi().getDid());

        OrderServiceImpl orderService = new OrderServiceImpl();
        int result = orderService.addOrder(hOrder);
        session.setAttribute("oo", hOrder);
        resp.sendRedirect("/pay.jsp");
    }
}
